package com.zf.bm.common.core.sys.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zf.bm.common.core.base.service.BaseService;
import com.zf.bm.common.core.sys.dao.RoleDao;
import com.zf.bm.common.core.sys.entity.Role;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@DS("master")
@Transactional(readOnly = true)
@CacheConfig(cacheNames="roleList")
public class RoleService  extends BaseService<RoleDao, Role> {

    public Role getByName(Role role){

        return this.getOne(Wrappers.lambdaQuery(new Role()).eq(Role::getName,role.getName()));
    }
    /**
     * 维护角色与菜单权限关系
     * @return
     */
    @CacheEvict(key = "#id")
    public int deleteRoleMenu(Long id){
        return baseMapper.deleteRoleMenu(id);
    }
    @CachePut(key = "#p0.enname")
    public int insertRoleMenu(Role role){
        return baseMapper.insertRoleMenu(role);
    }

    public Role selectNameAndSm3ById(Integer id) {
        return baseMapper.selectNameAndSm3ById(id);
    }
}
